06. Exercise: Create and Initialize a Paint and a Path Object

23 6 AAK Paint And Path SC V2

Android Developer Documentation

Exercise

In this exercise you will create and initialize a Paint and a Path Object.

  1. Switch to the ClippedView class.

  2. In ClippedView define a variable paint of a Paint.

    a. Enable anti-aliasing,

    b. and use the stroke width and

    c. text size defined in the dimensions.

private val paint = Paint().apply {
   // Smooth out edges of what is drawn without affecting shape.
   isAntiAlias = true
   strokeWidth = resources.getDimension(R.dimen.strokeWidth)
   textSize = resources.getDimension(R.dimen.textSize)
}
  1. In ClippedView, create and initialize a path variable of a Path to store locally the path of what has been drawn. Import android.graphics.Path.
private val path = Path()